
import { getHtml, getDevRender } from '../client/build.js'

const ENV = process.env.NODE_ENV?.trim().toLowerCase()

const renderViteBind = (ctx) => {
  return async(page) => {
    ctx.set('Content-Type', 'text/html')
    if(ENV == 'dev'){
      ctx.body = await getDevRender(ctx, page)
    }else{
      ctx.body = getHtml(page)
    }
  }
}

export default async(ctx, next) => {
  ctx.renderVite = renderViteBind(ctx)
  await next()
}